package org.example.redis.controller;

import org.example.redis.utils.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/stock")
public class SetStockController {
    @Autowired
    private StringRedisTemplate stringRedisTemplate;
    @PostMapping("/set")
    public JsonResult set(@RequestParam("id") int id,@RequestParam("stock") int stock){
        stringRedisTemplate.opsForValue().set("goods-stock:"+id, String.valueOf(stock));
        return JsonResult.success("设置成功",null);
    }
}
